<?php

namespace addons\sum\controller;


use addons\sum\controller\Base;
use app\admin\model\sum\Slideshows as SlideshowsModel;
use addons\sum\model\Slides as SlidesModel;

class Slides extends Base
{

    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    // 轮播图 列表
    public function index()
    {
        $slug=$this->request->request('slug','home');
        $per_page=$this->request->request('per_page','10');
        $slideShow=SlideshowsModel::where('slug',$slug)->find();
        if(!$slideShow){
            $this->error('参数错误');
        }
        $slides=SlidesModel::where('slideshow_id',$slideShow['id'])->where('status','normal')->Order('weigh DESC')->paginate($per_page);
        $slides->each(function ($slide){
            $lang_record=$this->doLangData($slide['lang_data']);
            //合并数组 - 在模型中配置属性，如 image 使用 cdnurl,是在最终的结果时处理的。所以这里直接覆盖 image 就行，不用提前在处理数据
             if(!empty($lang_record)){
                foreach ($lang_record as $lk=>$lv){
                    $slide[$lk]=$lv;
                }
            }
            unset($slide['lang_data']);
        });
        $this->success('操作成功', $slides);
    }


}
